/*
 * FunctionGenerators.js
 *
 * COS452
 * Alex Grant
 * 
 */
 
 /*
  * An annoying sine function
  */
function sineFunctionGenerator() {}
	sineFunctionGenerator.prototype = {
		"tick" : 0,
                "gain" : 50,
                "increment" : 1,
		
                //--------------------------------------------------------------------------------------------
                // public methods
                //--------------------------------------------------------------------------------------------
                "getValue" : function() {
			var value = this.gain * Math.sin(this.tick * (Math.PI/180));
                        this.tick += this.increment;
                        return value;
		},
		
		"peekNext" : function() {
			return this.gain * Math.sin(this.tick * (Math.PI/180));
		},
		
		"getMin" : function() {
			return this.gain * -1;
		},
		
		"getMax" : function() {
			return this.gain;
		}
	}
var sineGenerator = new sineFunctionGenerator();

/*
 * An L System with musical relationships
 */
function lsysFunctionGenerator() {} 
	lsysFunctionGenerator.prototype = {
		"index" : 1,
		"depthMax": 98,
		"min" : 10,
		"max" : 22,
		"system" : [
			[],[],[],[],[],[],[],[],[],[],
			[10, 15, 12,  null],
			[],
			[12, 10, 18, 13, null],
			[13, 18, 17, 20, null],
			[],
			[15, 13, 12, null],
			[],
			[17, 15, 17, 22, null],
			[18, 10, 13, null],
			[],
			[20, 18, 17, 18, null],
			[],
			[22, 18, 20, 17, null]
		],
		"q" : [ [22, 22, null] ],
		
                //--------------------------------------------------------------------------------------------
                // public methods
                //--------------------------------------------------------------------------------------------
                "getValue" : function() {
			var val = this.q[0][this.index++];
			if (val == null) {
				this.index = 1;
				this.q.shift();
				val = this.q[0][this.index++];
			}
			if (this.q.length < this.depthMax) {
				this.q.push(this.system[val]);
			}
			//echo(1, "llen="+this.q.length+", index="+this.index);
			//echo(2, "peek="+this.peekNext());
			return val;
		},
		
		"peekNext" : function() {
			var val = this.q[0][this.index];
			if (val == null) {
				if (this.q[1] != null)
					val = this.q[1] [1];
			}
			return val;
		},
		
		"getMin" : function() {
			return this.min;
		},
		
		"getMax" : function() {
			return this.max;
		}		
	}
var lsysGenerator = new lsysFunctionGenerator();

/*
 * Mary Had A Little Lamb
 */
function maryHALLFunctionGenerator() {}
	maryHALLFunctionGenerator.prototype = {
		"index" : 0,
		"min" : 11,
		"max" : 17,
		"notes" : [
			15, 13, 11, 13, 15, 15, 15, 13, 13, 13, 15, 18, 18, 15, 13, 11, 13, 15, 15, 15, 15, 13, 13, 15, 13, 11, null
		],
		
                //--------------------------------------------------------------------------------------------
                // public methods
                //--------------------------------------------------------------------------------------------
                "getValue" : function() {
			var val = this.notes[this.index++];
			if (val == null) {
				this.index = 0;
				val = this.notes[this.index++];
			}
			//alert(val);
			return val;
		},
		
		"peekNext" : function() {
			var val = this.notes[this.index];
			if (val == null) {
				val = this.notes[0];
			}
			return val;
		},
		
		"getMin" : function() {
			return this.min;
		},

		"getMax" : function() {
			return this.max;
		}
	}
var maryHALLGenerator = new maryHALLFunctionGenerator();